import get_params from '@dfeidao/atom-nodejs/authorization/get-params';
import { IFeidaoAiNodejsComponent } from '@dfeidao/atom-nodejs/interfaces';
import nodejs from '@dfeidao/atom-nodejs/msg/nodejs';
import whoami from '@dfeidao/atom-nodejs/msg/whoami';
import render from '@dfeidao/atom-nodejs/render/render';
import { file_url, spaceid } from '../../atom/config';
import p001 from './p001';
import p002 from './p002';

export default async function na001(fd: IFeidaoAiNodejsComponent) {
	const user = await whoami(fd.data.actionid, fd.data.sessionid);
	const admin = await get_params(fd.data.msg, fd.data.headers, user.productid, '3') as {
		headimg: string
		staff_no: string

	};
	const productid = user.productid;
	const res = await nodejs<{ dataArray: Array<{}> }>(fd.data.actionid, fd.data.sessionid, 'common/zjc-000002/s003', { productid });

	const res2 = await nodejs<{ dataArray: Array<{ headimg: string }> }>(fd.data.actionid, fd.data.sessionid, 'common/zjc-000002/s002', { productid, staff_no: admin.staff_no });


	if (!res2.dataArray[0]) {
		admin.headimg = './images/login-logo.png';
	} else {
		admin.headimg = `${file_url}/getfile?productid=${spaceid}&id=${res2.dataArray[0].headimg}`;
	}
	render(fd.data.node, res.dataArray[0], p002, 'p002');
	render(fd.data.node, admin, p001, 'p001');
}
